package com.riant.day03.demo03;
import	java.io.FileOutputStream;
import	java.io.FileInputStream;

import java.io.File;
import java.nio.charset.Charset;

/**
 * @Classname TestFile3
 * @Description TODO
 * @Date 2021/3/5 23:31
 * @Created by 张斌
 */
public class TestFile3 {

    public static void main(String[] args) {
        File source = new File("day01\\src\\main\\java\\com\\riant\\day03\\demo03\\a.txt");
        File dest=new File("day01\\src\\main\\java\\com\\riant\\day03\\demo03\\backa.txt");
        //copyFile(source,dest);
        copyFile2();
    }

    public static void copyFile(File source,File dest){
        try {
            FileInputStream fis = new FileInputStream(source);
            FileOutputStream fos = new FileOutputStream(dest);
            byte[] buf=new byte[1024];
            int len=0;
            while((len=fis.read(buf))!=-1){
                String str=new String(buf,0,len);
                fos.write(str.getBytes(Charset.forName("utf-8")));
            }
            fos.close();
            fis.close();
        }catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void copyFile2(){
        File source = new File("day01\\src\\main\\java\\com\\riant\\day03\\demo03\\1.png");
        File dest=new File("day01\\src\\main\\java\\com\\riant\\day03\\demo03\\2.png");
        try {
            FileInputStream fis = new FileInputStream(source);
            FileOutputStream fos = new FileOutputStream(dest);
            byte[] buf=new byte[1024];
            int len=0;
            while((len=fis.read(buf))!=-1){
                fos.write(buf,0,len);
            }
            fos.close();
            fis.close();
        }catch (Exception e) {
            e.printStackTrace();
        }
    }
}
